﻿using ZR.Model.Souvenir;
using ZR.Model.Souvenir.Dto;
using ZR.Service.Souvenir.IService;

namespace ZR.Admin.WebApi.Controllers.Souvenir
{
    [Route(("souvenir/orderItem/item"))]
    public class OrderItemItemController : BaseController
    {
        private readonly IOrderItemService _orderItemService;

        public OrderItemItemController(IOrderItemService orderItemService)
        {
            _orderItemService = orderItemService;
        }
        
        [HttpPost("addOrderItem")]
        public async Task<IActionResult> AddOrderItem([FromBody] OrderItem orderItem)
        {
            return SUCCESS(await _orderItemService.InsertOrderItemAsync(orderItem) > 0);
        }

        [HttpPut("updateOrderItem")]
        public async Task<IActionResult> UpdateOrderItem([FromBody] OrderItem orderItem)
        {
            return SUCCESS(await _orderItemService.UpdateOrderItemAsync(orderItem) > 0);
        }
        
        [HttpDelete("deleteOrderItem/{orderItemId}")]
        public async Task<IActionResult> DeleteOrderItem(int orderItemId)
        {
            return SUCCESS(await _orderItemService.DeleteOrderItemAsync(orderItemId) > 0);
        }
        
        [HttpPost("getOrderItemWithPage")]
        public async Task<IActionResult> GetOrderItemWithPage([FromBody] OrderItemQueryDto orderItemQueryDto)
        {
            return SUCCESS(await _orderItemService.SelectOrderItemWithPageAsync(orderItemQueryDto));
        }
        
        [HttpGet("getOrderItemById/{orderItemId}")]
        public async Task<IActionResult> GetOrderItemById(int orderItemId)
        {
            return SUCCESS(await _orderItemService.SelectOrderItemAsyncById(orderItemId));
        }
    }
}